package zzps.exeed.kernel.holder;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class FieldHolder {

    private PandaHolder pandaHolder;
    private Field field;
    private Annotation[] annotations;
    private Class<?> clazz;
    private Object value;
    public FieldHolder(PandaHolder pandaHolder, Field field) {
        this.pandaHolder = pandaHolder;
        field.setAccessible(true);
        this.field = field;
        annotations = field.getDeclaredAnnotations();
        clazz = field.getType();
    }

    public Annotation[] getAnnotations() {
        return annotations;
    }

    public PandaHolder getPandaHolder() {
        return pandaHolder;
    }

    public void setValue(Object value) {
        if (value != null){
            try {
                field.set(pandaHolder.raw(),value);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
        this.value = value;
    }

    public Object getValue() {
        return value;
    }

    public Class<?> getType() {
        return clazz;
    }

}
